package edu.study.common.exception;

import edu.study.api.common.dto.BaseRespDto;
import edu.study.api.common.enums.BaseResultCodeEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * Created by za-daixiaojun on 2017/11/7.
 */
@Slf4j
public class ExceptionHandler {
    
    public static <T extends BaseRespDto> T handleProcessing(T resp, Throwable t) {
        if (t instanceof BizException) {
            BizException e = (BizException) t;
            resp.setResultCode(e.getCode());
            resp.setResultMessage(e.getMessage());
        } else {
        	resp.setResultFail(BaseResultCodeEnum.EXCEPTION);
        }
        log.error(t.getMessage(), t);
        return resp;
    }

    public static <T extends BaseRespDto> T handleFailFast(T resp, Throwable t) {
        if (t instanceof BizException) {
            BizException e = (BizException) t;
            resp.setResultCode(e.getCode());
            resp.setResultMessage(e.getMessage());
        } else {
        	resp.setResultFail(BaseResultCodeEnum.EXCEPTION);
        }
        log.error(t.getMessage(), t);
        return resp;
    }
}
